var headurl = `https://chinawzhs.cn/api/`
//`https://bwv.net.cn/${__wxConfig.envVersion == 'trial' ? 'prod' :'api'}`;




var imgurl = `${headurl}imgs/`,
  staticimgurl = `${headurl}static/`,
  audiourl = `${headurl}audio/`
class api {

 
  getheadurl() {
    return headurl;
  }
  
  getstaticimg() {
    return 'https://chinawzhs.cn/bak/static/';
  }
  getimgurl() {
    return imgurl;
  }
  getstaticimgurl() {
    return staticimgurl;
  }
  getaudiourl() {
    return audiourl;
  }
  /**
   * 登录
   */
  wxlogin(code, success, fail) {
    fstpostdata('/login/wxlogin', {
      jscode: code
    }, res => success(res), res => fail&&fail(res))
  }

  uploadimg(data, params) {
    // console.log(data,params,"q11fesfds");
    // return;

    var that = this,
      i = data.i ? data.i : 0, //当前上传的哪张图片
      success = data.success ? data.success : 0, //上传成功的个数
      fail = data.fail ? data.fail : 0, //上传失败的个数
      pics = data.pics ? data.pics : [];
    // console.log(data.path[i]);
    wx.uploadFile({
      header: {
        'content-type': "application/x-www-form-urlencoded",
        token: getApp().logininfo.Token,
        userid: getApp().logininfo.userid
      },
      url: data.url,
      filePath: data.path[i],
      name: 'upload', //这里根据自己的实际情况改
      formData: null, //这里是上传图片时一起上传的数据
      success: (resp) => {
        success++; //图片上传成功，图片上传成功的变量+1

        let result = JSON.parse(resp.data);
        pics.push(result.path);
        console.log(pics, "picssss")
        //这里可能有BUG，失败也会执行这里,所以这里应该是后台返回过来的状态码为成功时，这里的success才+1 
      },
      fail: (res) => {
        fail++; //图片上传失败，图片上传失败的变量+1
        console.log('fail:' + i + "fail:" + fail);
      },
      complete: () => {
        console.log(i);

        i++; //这个图片执行完上传后，开始上传下一张            
        if (i == data.path.length) { //当图片传完时，停止调用          
          console.log('执行完毕');
          console.log('成功：' + success + " 失败：" + fail);

          params.success(pics);

        } else { //若图片还没有传完，则继续调用函数                
          console.log(i);
          data.i = i;
          data.success = success;
          data.fail = fail;
          data.pics = pics;
          that.uploadimg(data, params);
        }
      }
    });
  }

  // start王林洁

//   // 获取订单详情
//   getfinishorderdetail(ordernum,succ) {
//   postdata('Orders/bk_getorderdetail', {ordernum}, res => succ(res))
// }
  // 获取订单详情
  getfinishorderdetail(ordernum,succ) {
    postdata('Orders/bk_getorderdetail1', {ordernum}, res => succ(res))
  }


  // 前端获取轮播图列表
  // Lbimgs/ft_getlist
  getBaanerList(succ) {
    postdata('Lbimgs/ft_getlist', {}, res => succ(res))
  }





  // 前端获取商品分类列表
  // Goodstype/ft_getlist
  getCommodityList(succ) {
    postdata('Goodstype/ft_getlist', {}, res => succ(res))
  }

  // 前端获取全部商品列表
  // Goods/ft_getall
  getAllCommodityGoods(data, succ) {
    postdata('Goods/ft_getall', data, res => succ(res))
  }

  // 前端根据分类获取商品列表
  // Goods / ft_getlistbycids
  getCommodityGoods(data, succ) {
    postdata('Goods/ft_getlistbycid', data, res => succ(res))
  }
  // 前端获取商品详情
  // Goods/ft_getdetail
  // id
  getGoodsDetail(id, succ) {
    postdata('Goods/ft_getdetail', {id}, res => succ(res))
  }
//   前端获取收货地址列表
//   Address/ft_getlist
// userid
getaddresslist( succ) {
  postdata('Address/ft_getlist', {  }, res => succ(res))
}
  // 前端添加/编辑收货地址
  // Address / ft_aoe
  // id  可选
  // userid
  // name
  // phone
  // province  省份
  // city   市
  // county 县 / 区
  // street  街道
  // isdefault 0 非默认 1 默认
addAddress(data, succ) {
  postdata('Address/ft_aoe', data, res => succ(res))
}
//   前端获取地址详情
//   Address/ft_getdetail
// id
  getaddAddressDetail(id, succ) {
    postdata('Address/ft_getdetail', { id }, res => succ(res))
  }
//   前端删除收货地址
//   Address/ft_deladdress
// id
// userid
  deladdress(id, succ) {
    postdata('Address/ft_deladdress', { id }, res => succ(res))
  }
//   前端取消/设为默认地址
// Address / ft_setdefault
// id
  setaddresscheck(id, succ) {
    postdata('Address/ft_setdefault', { id }, res => succ(res))
}
//   用户购物车添加商品
//   Cart/ft_cartadd
// userid
// goodscount 商品数量
// price  总价格
// goodsnum  商品编号
addshoppingCart(data, succ) {
  postdata('Cart/ft_cartadd', data, res => succ(res))
}
//   用户获取购物车列表
//   Cart/ft_getcarts
// userid
// start
// pagesize
  getCartlist(data, succ) {
    postdata('Cart/ft_getcarts', data, res => succ(res))
  }
//   用户购物车删除商品
//   Cart/ft_delcart
// id
// userid
// start
// pagesize
  delCartlist(data, succ) {
    postdata('Cart/ft_delcart', data, res => succ(res))
  }

  //获取用户最新一次订单详情
   getuserorder(succ){
  postdata('Orders/getuserorder',{}, res => succ(res))
}

  // 前端获取美食秀秀列表
getshowlist(data, succ) {
    postdata('Cateshow/ft_getlist', data, res => succ(res))
  }
   // 前端获取美食秀秀关注列表
   getshowfocuslist(data, succ) {
    postdata('Cateshow/ft_getlist', data, res => succ(res))
  }
  
  // 前端发布美食秀秀
  addshows(data, succ) {
    postdata('Cateshow/ft_add', data, res => succ(res))
  }
  
  
  // 前端获取我的美食秀秀列表
  getmyshowlist(data, succ) {
    postdata('Cateshow/ft_getmylist', data, res => succ(res))
  }
//前端获取美食秀秀详情
  getmyshowdetail(data, succ) {
      postdata('Cateshow/ft_getdetail',data, res => succ(res))
    }
    // 前端美食点赞或取消
    // Cateshow/ft_favor
    // cateid 
give_the_thumbs_up(cateid, succ) {
    postdata('Cateshow/ft_favor',{cateid}, res => succ(res))
}
// 前端美食关注或取消
// Cateshow/ft_follow
// cateuserid
tofollow(cateuserid, succ) {
    postdata('Cateshow/ft_follow',{cateuserid}, res => succ(res))
}
//  前端美食秀秀添加评论
addcontents(data, succ) {
   postdata('Cateshow/ft_addcom',data, res => succ(res))
}
// 前端获取美食评论列表
getcontentslist(data, succ) {
   postdata('Cateshow/ft_getcomlist',data, res => succ(res))
}

// coupon/ft_getlistbypage
// 获取优惠券列表
// pagesize
// start
getCouponlist(data, succ) {
   postdata('coupon/ft_getlistbypage',data, res => succ(res))
}
// ----------------------
// users/getcoupon
// 领取优惠券
// cid

receivecoupon(cid,succ) {
  postdata('users/getcoupon',{cid}, res => succ(res))
}
// dishes/findbyid
// 获取菜谱详情
// id
getdishesdetails(id,succ) {
  postdata('dishes/findbyid',{id}, res => succ(res))
}

  // dishes/findbyid
  // 获取菜谱详情
  // id
  getrank(data, succ)  {
    postdata('dishes/getrank', data,  res  =>  succ(res))
  }
// scoregoods/getall
// （前端/后台）前端获取全部积分商品列表
// pagesize
// start
getscoregoodslist(data, succ) {
   postdata('scoregoods/getall',data, res => succ(res))
}
// scoregoods/getdetail
// （前端/后台）获取积分商品详情
// id
getscoregoodsdetails(id,succ) {
  postdata('scoregoods/getdetail',{id}, res => succ(res))
}

// 后台举报评论
// cateshow/report
// id
reportuser(id,succ) {
  postdata('cateshow/report',{id}, res => succ(res))
}
// users/getmine
// 我的页面获取信息
getmine( succ) {
  postdata('users/getmine', {  }, res => succ(res))
}
// 用户是否能购买积分商品
// scoregoods/canbuy
// id
canbuy(id,count,succ) {
  postdata('scoregoods/canbuy',{id,count}, res => succ(res))
}

// 用户是否能购买积分商品
// scoregoods/canbuy
// id
payscore(number,succ) {
  postdata('orders/payscore',{number}, res => succ(res))
}




// collection/collect
// 用户收藏/取消
// goodsid
// isscore T积分商品 F普通

collectiongoods(data, succ) {
   postdata('collection/collect',data, res => succ(res))
}

// collection/ft_getlist
// 前端获取我的收藏
// start
// pagesize
// isscore T积分商品 F普通

getcollectionlist(data, succ) {
   postdata('collection/ft_getlist',data, res => succ(res))
}

// cateshow/ft_getfolloworfanslist
// start
// pagesize
// isfollow 0关注 1粉丝

getfolloworfanslist(data, succ) {
   postdata('cateshow/ft_getfolloworfanslist',data, res => succ(res))
}

// cateshow/ft_getfolloworfanscounts
// 前端获取关注和粉丝数量
getfolloworfanscounts( succ) {
   postdata('cateshow/ft_getfolloworfanscounts',{}, res => succ(res))
}

// dishes/ft_gettwplist
// 获取所有调味品
gettwplist( succ) {
   postdata('dishes/ft_gettwplist',{}, res => succ(res))
}

// labels/ft_getinterestinglist
// 前端获取兴趣标签
getinterestinglist(succ) {
   postdata('labels/ft_getinterestinglist',{}, res => succ(res))
}

// card/getcard
// 获取卡信息
getcard(succ) {
   postdata('users/getcard',{}, res => succ(res))
}
// users/setcard
// 创建会员卡
setcard(data,succ) {
   postdata('users/setcard',data, res => succ(res))
}
// users/editcardinfo
// 修改会员信息
editcardinfo(data,succ){
   postdata('users/editcardinfo',data, res => succ(res))
}
// 解析手机号
// users/gete
// edata
// iv
getphone(data,succ){
   postdata('users/gete',data, res => succ(res))
}
// users/share
// 拉新操作
// shareuid share带的参数id
share(shareuid,path,succ){
     postdata('users/share',{shareuid,path}, res => succ(res))
  }
  // users/getsharelist
  // 获取拉新列表
  // start
  // pagesize
  
  getsharelist(data,succ){
     postdata('users/getsharelist',data, res => succ(res))
  }
  
  // users/getuserscorelist
  // 获取积分记录列表
  // start
  // pagesize
  getuserscorelist(data,succ){
     postdata('users/getuserscorelist',data, res => succ(res))
  }
  // users/getgrowthlist
  // 获取成长值记录列表
  // start
  // pagesize
  getgrowthlist(data,succ){
     postdata('users/getgrowthlist',data, res => succ(res))
  }

  // 获取我的优惠券
getmycouponlist(state,succ){
     postdata('coupon/ft_getmylist',{state}, res => succ(res))
  }

  // 我的奖品
getmyawardlist(data, succ) {
    postdata('awards/ft_getmyawardlist', data, res => succ(res))
  }


// end王林洁

// 刘宜婷
// 抽奖活动
  awardsgetlist(data,succ){
        postdata('awards/ft_getlist',data, res => succ(res))
      }
  // pagesize
  // start
  
  // 抽奖活动详情
  awardsfindbyid(id,succ){
        postdata('awards/findbyid',{id}, res => succ(res))
      }
  // id
  
  // 获取抽奖的奖品
  awardsgetallg(id,succ){
        postdata('awards/bk_getall_g',{id}, res => succ(res))
      }
  awardschou(id,succ){
          postdata('awards/chou',{id}, res => succ(res))
        }
    // id
//simon

  setCartcount(data, succ) {
    postdata('Cart/ft_setcount', data, res => succ(res))
  }

  // addorder(data,succ){
  //   postdata('orders/ft_createorder1', data, res => succ(res))
    
  // }
  addorder(data,succ){
    postdata('orders/ft_createorder3', data, res => succ(res))
    
  }

  order_list(data, succ) {
    postdata('orders/ft_getlistbystate1', data, res => succ(res))

  }

  updateUser(data, succ) {
    postdata('users/updateUser', data, res => succ(res))

  }

  getshowfocuslist(data, succ) {
    postdata('cateshow/ft_getmyfollowlist', data, res => succ(res))
  }

  getshowfocuspeoplelist(data, succ) {
    postdata('cateshow/ft_getfolloworfanslist', data, res => succ(res))
  }

  getshowfocuspeoplecounts( succ) {
    postdata('cateshow/ft_getfolloworfanscounts', {}, res => succ(res))
  }

  getnews(data, succ) {
    postdata('cateshow/ft_getnews', data, res => succ(res))
  }

  addscoreorder(data, succ) {
    postdata('orders/ft_createsorder', data, res => succ(res))
  }

  

  /**
   * 2020-01-09
   * 
   */
  usergetrank(data, succ) {
    postdata('dishes/usergetrank', data, res => succ(res))
  }

  getavailablecoupon(data, succ) {
    postdata('users/getavailablecoupon', data, res => succ(res))
  }

 /**
   * 2020-01-09
   * 
   */
  

  

 

  refund(number, succ) {
    postdata('orders/refund', {number}, res => succ(res))
  }

  cancelorder(data, succ) {
    postdata('orders/cancel', data, res => succ(res))
  }

  testpay(number,issucc, succ) {
    postdata('orders/testpay', {number,succ:issucc}, res => succ(res))
  }

  
  getorderdetail(ordernum,succ){
    postdata('orders/ft_findbynum', {ordernum}, res => succ(res))
  }
    //实验室
    getlablist(data,succ){
      postdata('dishes/ft_getlist', data, res => succ(res))
    }

  //抽奖管理
    getawardslist(data,succ){
        postdata('awards/ft_getlist', data, res => succ(res))
      }
//用户领奖到口袋
  getawardsintopocket(id, succ) {
    postdata('awards/ft_getmyawardintopocket', {id},  res  =>  succ(res))
  }

    getswipers(succ){
      postdata('lbimgs/获取轮播图',{}, res => succ(res))
    }

    setlabels(data,succ){
      postdata('users/setlabels',data, res => succ(res))
    }

//---------------------------

    //刘宜婷0229
        // 获取城市列表
    getcitylist(succ){
      postdata('city/ft_getlist',{}, res => succ(res))
    }
    // 提交反馈
    addfeedback(data,succ){
      postdata('Feedback/ft_addfeedback',data, res => succ(res))
    }
    // 获取绿色行动
    getrichtext(succ){
      postdata('Greenaction/ft_getrichtext',{}, res => succ(res))
    }
    // // 获取价钱列表
    // Pricelistgetlist(district,succ){
    //   postdata('Pricelist/ft_getmylist',{district}, res => succ(res))
    // }
    // 获取价钱列表1
    Pricelistgetlist(data,succ){
      postdata('Pricelist/ft_getmylist1',data, res => succ(res))
    }
     // 获取废品一级分类
     Recycletypegetlist(succ){
      postdata('Recycletype/ft_getlist',{}, res => succ(res))
    }

      // 获取废品一级分类
      Recycletypegetlist1(succ){
        postdata('Recycletype/ft_getlist1',{}, res => succ(res))
      }


     // 获取废品二级分类
    //  Recycletypegetlister(tid,succ){
    //   postdata('Recycletype/ft_getlister1',{tid,city:wx.getStorageSync('city')}, res => succ(res))

    // }
    // 获取废品二级分类
     Recycletypegetlister(tid,succ){
      postdata('Recycletype/ft_getlister2',{tid,district:wx.getStorageSync('district')}, res => succ(res))

    }

  // 判断分类权限
  checkrecycleright(data,succ){
    postdata('Recycletype/bk_checkright1',data, res => succ(res))
  }

    
    //前端获取所有二级分类    
    getallsublist(succ){
      postdata('Recycletype/ft_getallsublist',{}, res => succ(res))
    }
    // // 收藏/取消
    // collect(data,succ){
    //   postdata('Collection/collect',data, res => succ(res))
    // }
 //支付成功添加储值记录
 afterpay(data,succ){
  postdata('orders/afterpay',data, res => succ(res))
}

getuserstorage(succ){
  postdata('Storage/getuserstorage',{}, res => succ(res))
}


 //前端获取充值列表
 getrecordlist(data,succ){
  postdata('Storage/ft_getrecordlist',data, res => succ(res))
}
 //获取积分订单详情
 getscoreorderdetail(ordernum,succ){
  postdata('ScoreOrders/bk_getorderdetail',{ordernum}, res => succ(res))
}
 //更新经纬度
 setlatlng(data,succ){
  postdata('Users/bk_setlatlng',data, res => succ(res))
}
 //前端获取积分记录
 getscorelist(data,succ){
  postdata('Users/bk_getscorelist1',data, res => succ(res))
}
 //前端获取储值记录
 getstoragelist(data,succ){
  postdata('Storage/ft_getstoragelist2',data, res => succ(res))
}
 //前端获取附近的回收员
 getnearbylist(district,succ){
  // district = '东营区'
 postdata('Users/bk_getnearbylist',{district}, res => succ(res))
}
 //获取分类知识
 Classificationgetall(succ){
  postdata('Classification/ft_getall',{}, res => succ(res))
}
 //获取分类知识
 Classificationgetdetail(id,succ){
  postdata('Classification/bk_getdetail',{id}, res => succ(res))
}
 //回收员设置调单
 setturning(ordernum,succ){
  postdata('Orders/setturning',{ordernum}, res => succ(res))
}

 //获取代理下的回收员调单的订单
 getturninglist(succ){
  postdata('Orders/ft_getturninglist',{}, res => succ(res))
}
 //调单成功
 setturningtrue(data,succ){
  postdata('Orders/setturningtrue',data, res => succ(res))
}
//前端代理获取旗下员工列表
getmyuserslist(succ){
  postdata('Users/ft_getmyuserslist',{}, res => succ(res))
}
//前端代理获取旗下员工列表
getmyuserslist1(ordernum,succ){
    postdata('Users/ft_getmyuserslist1',{ordernum}, res => succ(res))
  }
//代理统计
getstatistics(data,succ){
  postdata('Users/ft_getstatistics1203',data, res => succ(res))
}
//记录登录昵称和头像
getnameurl(data,succ){
  postdata('Users/ft_getnameurl',data, res => succ(res))
}
//代理获取旗下员工位置列表
getmyusersaddresslist(succ){
  postdata('Users/ft_getmyusersaddresslist',{}, res => succ(res))
}
//根据地区获取客服电话
getservicephone(succ){
  postdata('Users/bk_getphone',{}, res => succ(res))
}
 // 发起提现
 WithdrawalApplycreateapply(money, succ) {
  postdata('WithdrawalApply/ft_createapply1', {money}, res => succ(res))
}

  updatedistrict(district,city,succ){
    
    postdata('users/ft_consumer_changedistrict', { district,city }, res => succ&&succ(res))
  }
  // 删除订单
  delorder(number, succ) {
    postdata('orders/ft_delorder', {number}, res => succ(res))
  }

    // end 刘宜婷0229 

    memberapply(data,succ) {
      postdata('apply/add1', data, res => succ(res))
    }

    // memberapply(data,succ) {
    //   postdata('apply/add1', data, res => succ(res))
    // }

    getmyapply(data,succ) {
      postdata('apply/getmyapply', data, res => succ(res))
    }

    getdistricts(name,succ) {
      postdata('city/ft_getdistricts', {name}, res => succ(res))
    }

    getuseabledistrict(city,succ) {
      postdata('city/getuseabledistrict', {city}, res => succ(res))
    }

    canorder(data,succ){
      postdata('city/ft_canorder', data, res => succ(res))
    }

    createscoreorder(data,succ){
      postdata('ScoreOrders/ft_createorder', data, res => succ(res))
    }

    // getorderlistbystate(data,succ){
    //   postdata('orders/ft_getlistbystate1', data, res => succ(res))
    // }
    getorderlistbystate(data,succ){
      postdata('orders/ft_getlistbystate2', data, res => succ(res))
    }
  
    // getorderinglist(data,succ){
    //   postdata('orders/ft_getorderinglist3', data, res => succ(res))
    // }
    getorderinglist(succ){
      postdata('orders/ft_getorderinglist4', {}, res => succ(res))
    }
    recyclercancel(ordernum,succ){
      postdata('orders/ft_recyclercancel', {ordernum}, res => succ(res))
    }

    recycleraccept(ordernum,succ){
      postdata('orders/ft_recycleraccept2', {ordernum}, res => succ(res))
    }

    recycleconfirm(data,succ){
      postdata('orders/ft_recyclerconfirm1',data, res => succ(res))
    }

    userassess(data,succ){
      postdata('orders/ft_userassess', data, res => succ(res))
    }

    checkshare(shareid,succ){
      postdata('users/checkshare', {shareid}, res => succ(res))
    }

      // //前端获取储值列表  
      // getstoragelist(data,succ){
      //   postdata('users/ft_getstoragelist', data, res => succ(res))
      // }

      //获取支付方式
      getpaytype(ordernum,succ){
        postdata('main/getpaymenttype', {ordernum}, res => succ(res))
      }

      //获取代理的员工订单列表
      getmymemberlist(data,succ){
        postdata('orders/ft_getmymemberlist1', data, res => succ(res))
      }

       //前端获取所有积分订单列表
 getseoreorderslist(data,succ){
    postdata('ScoreOrders/ft_getseoreorderslist',data, res => succ(res))
  }
     //打印日志
writelog(data,succ){
    postdata('login/writelog',data, res =>succ&& succ(res))
  }

 /**
  * 装车入库
  * 
  */
//一键装车
 gocar(succ) {
  postdata('store/newcar', {}, res => succ(res))
}
keeper_sumbit(data,succ) {
  postdata('store/submit', data, res => succ(res))
}
keeper_getlist(type,succ){
  postdata('store/storekeeper_getlist', {type}, res => succ(res))
}
keeper_getmylist(type,succ){
  postdata('store/getmylist', {type}, res => succ(res))
}

keeper_getdetail(storeid,succ){
  postdata('store/storekeeper_getdetail', {storeid}, res => succ(res))
}

 
  prepay(data, succ, fail) {
    data['openid'] = wx.getStorageSync('openid')
    postdata('/orders/pay', data, res => {
      var data = JSON.parse(res.data.res);
      var orderid = data.orderid;
      wx.requestPayment({
        timeStamp: data.timeStamp,
        nonceStr: data.nonce_str,
        package: data.package,
        paySign: data.paySign,
        signType: 'MD5',
        success: res => {
          console.log(res, 'succ')
          if (res.errMsg.indexOf('ok') > -1) {
            succ && succ({
              succ: 1,
              orderid
            })
          }
        },
        fail: res => {
          //支付取消
          succ && succ({
            succ: -1
          })
        }
      })
    })
  }
}

function postdata(urlparms, data, success, fail) {
  wx.showLoading({
    title: '加载中',
  })
  wx.request({
    url: headurl + urlparms,
    method: "POST",
    data: data,
    header: {
      'content-type': "application/x-www-form-urlencoded",
      token: getApp().logininfo.Token,
      userid: getApp().logininfo.userid
    },
    success: res =>{
    success(res)
    } 
    ,fail: res => fail && fail(res)
    ,complete:res=>{
      console.log(res,'complete-postdata')
      wx.hideLoading({
        success: (res) => {},
      })
    }
  })
}

function getdata(urlparms, data, success, fail) {

  wx.request({
    url: headurl + urlparms,
    data: data,
    header: {
      'content-type': "application/x-www-form-urlencoded",
      'userId': getApp().userinfo.userId,
    },
    success: res => success(res),
    fail: res => fail && fail(res)
  })
}

function fstpostdata(urlparms, data, success, fail) {
  wx.request({
    url: headurl + urlparms,
    method: "POST",
    data: data,
    header: {
      'content-type': "application/x-www-form-urlencoded",
    },
    success: res => success(res),
    fail: res => fail && fail(res),
    complete:res=>{
      console.log(res,'complete-postdata')
      wx.hideLoading({
        success: (res) => {},
      })
    }
    
  })
}



module.exports = api